unit Class_Unit;


interface
uses
  Classes,SysUtils,DB,Uni,UniEngine;

type
  TUNIT=class(TUniEngine)
  private
    FUNITLINK : string;
    FUNITCODE : string;
    FUNITNAME : string;
    FUNITCALL : string;
    FUNITADDR : string;
    FUNITKIND : string;
    FUNITLEVL : Integer;
    FUNITPREV : string;
    FUNITMEMO : string;
    FUNITABBR : string;
    FUNITIDEX : Integer;
    FUNITORDR : Integer;
    FHOLDBANK : string;
    FOTHRBANK : string;
    FFINAMTCH : string;
    FBASEMTCH : string;
    FISPECIAL : Integer;
    FSUBJLINK : string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;
  published
    property UNITLINK : string read FUNITLINK  write FUNITLINK;
    property UNITCODE : string read FUNITCODE  write FUNITCODE;
    property UNITNAME : string read FUNITNAME  write FUNITNAME;
    property UNITCALL : string read FUNITCALL  write FUNITCALL;
    property UNITADDR : string read FUNITADDR  write FUNITADDR;
    property UNITKIND : string read FUNITKIND  write FUNITKIND;
    property UNITLEVL : Integer read FUNITLEVL  write FUNITLEVL;
    property UNITPREV : string read FUNITPREV  write FUNITPREV;
    property UNITMEMO : string read FUNITMEMO  write FUNITMEMO;
    property UNITABBR : string read FUNITABBR  write FUNITABBR;
    property UNITIDEX : Integer read FUNITIDEX  write FUNITIDEX;
    property UNITORDR : Integer read FUNITORDR  write FUNITORDR;
    property HOLDBANK : string read FHOLDBANK  write FHOLDBANK;
    property OTHRBANK : string read FOTHRBANK  write FOTHRBANK;
    property FINAMTCH : string read FFINAMTCH  write FFINAMTCH;
    property BASEMTCH : string read FBASEMTCH  write FBASEMTCH;
    property ISPECIAL : Integer read FISPECIAL  write FISPECIAL;
    property SUBJLINK : string read FSUBJLINK  write FSUBJLINK;
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AUNIT:TUNIT):TUNIT;overload;
    class procedure CopyIt(AUNIT:TUNIT;var Result:TUNIT);overload;
  public
    class procedure SelectDB(Params:string);
    class procedure DeleteDB(Params:string);
    class procedure UpdateDB(Params:string);
  end;

implementation

uses
  Vcl.Dialogs;

{ TUNIT }
class procedure TUNIT.SelectDB(Params: string);
begin
  ShowMessageFmt('HI.I AM SELECTDB IN CLASS.%S',[Params]);
end;

procedure TUNIT.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('UNIT_CODE').Value := UNITCODE;
        ParamByName('UNIT_NAME').Value := UNITNAME;
        ParamByName('UNIT_CALL').Value := UNITCALL;
        ParamByName('UNIT_ADDR').Value := UNITADDR;
        ParamByName('UNIT_KIND').Value := UNITKIND;
        ParamByName('UNIT_LEVL').Value := UNITLEVL;
        ParamByName('UNIT_PREV').Value := UNITPREV;
        ParamByName('UNIT_MEMO').Value := UNITMEMO;
        ParamByName('UNIT_ABBR').Value := UNITABBR;
        ParamByName('UNIT_IDEX').Value := UNITIDEX;
        ParamByName('UNIT_ORDR').Value := UNITORDR;
        ParamByName('HOLD_BANK').Value := HOLDBANK;
        ParamByName('OTHR_BANK').Value := OTHRBANK;
        ParamByName('FINA_MTCH').Value := FINAMTCH;
        ParamByName('BASE_MTCH').Value := BASEMTCH;
        ParamByName('I_SPECIAL').Value := ISPECIAL;
        ParamByName('SUBJ_LINK').Value := SUBJLINK;
      end;
      otEdit:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;
        ParamByName('UNIT_CODE').Value := UNITCODE;
        ParamByName('UNIT_NAME').Value := UNITNAME;
        ParamByName('UNIT_CALL').Value := UNITCALL;
        ParamByName('UNIT_ADDR').Value := UNITADDR;
        ParamByName('UNIT_KIND').Value := UNITKIND;
        ParamByName('UNIT_LEVL').Value := UNITLEVL;
        ParamByName('UNIT_PREV').Value := UNITPREV;
        ParamByName('UNIT_MEMO').Value := UNITMEMO;
        ParamByName('UNIT_ABBR').Value := UNITABBR;
        ParamByName('UNIT_IDEX').Value := UNITIDEX;
        ParamByName('UNIT_ORDR').Value := UNITORDR;
        ParamByName('HOLD_BANK').Value := HOLDBANK;
        ParamByName('OTHR_BANK').Value := OTHRBANK;
        ParamByName('FINA_MTCH').Value := FINAMTCH;
        ParamByName('BASE_MTCH').Value := BASEMTCH;
        ParamByName('I_SPECIAL').Value := ISPECIAL;
        ParamByName('SUBJ_LINK').Value := SUBJLINK;
      end;
      otDelt:
      begin
        ParamByName('UNIT_LINK').Value := UNITLINK;

      end;
    end;
  end;
end;

class procedure TUNIT.UpdateDB(Params: string);
begin

end;

function TUNIT.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_UNIT',['UNIT_LINK',UNITLINK],AUniConnection);
end;

function TUNIT.GetNextIdex: Integer;
begin
  ShowMessage('true.in.class.');
end;

function TUNIT.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TUNIT.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_UNIT WHERE   UNIT_LINK=:UNIT_LINK';
end;

function TUNIT.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_UNIT'
         +'    ( UNIT_LINK, UNIT_CODE, UNIT_NAME, UNIT_CALL, UNIT_ADDR'
         +'    , UNIT_KIND, UNIT_LEVL, UNIT_PREV, UNIT_MEMO, UNIT_ABBR'
         +'    , UNIT_IDEX, UNIT_ORDR, HOLD_BANK, OTHR_BANK, FINA_MTCH'
         +'    , BASE_MTCH, I_SPECIAL, SUBJ_LINK)'
         +'    VALUES'
         +'    (:UNIT_LINK,:UNIT_CODE,:UNIT_NAME,:UNIT_CALL,:UNIT_ADDR'
         +'    ,:UNIT_KIND,:UNIT_LEVL,:UNIT_PREV,:UNIT_MEMO,:UNIT_ABBR'
         +'    ,:UNIT_IDEX,:UNIT_ORDR,:HOLD_BANK,:OTHR_BANK,:FINA_MTCH'
         +'    ,:BASE_MTCH,:I_SPECIAL,:SUBJ_LINK)';
end;

function TUNIT.GetStrsIndex: string;
begin
  Result:=Format('%S',[UNITLINK]);
end;

function TUNIT.GetStrUpdate: string;
begin
  Result:='UPDATE  TBL_UNIT SET'
         +'    UNIT_CODE=:UNIT_CODE,'
         +'    UNIT_NAME=:UNIT_NAME,'
         +'    UNIT_CALL=:UNIT_CALL,'
         +'    UNIT_ADDR=:UNIT_ADDR,'
         +'    UNIT_KIND=:UNIT_KIND,'
         +'    UNIT_LEVL=:UNIT_LEVL,'
         +'    UNIT_PREV=:UNIT_PREV,'
         +'    UNIT_MEMO=:UNIT_MEMO,'
         +'    UNIT_ABBR=:UNIT_ABBR,'
         +'    UNIT_IDEX=:UNIT_IDEX,'
         +'    UNIT_ORDR=:UNIT_ORDR,'
         +'    HOLD_BANK=:HOLD_BANK,'
         +'    OTHR_BANK=:OTHR_BANK,'
         +'    FINA_MTCH=:FINA_MTCH,'
         +'    BASE_MTCH=:BASE_MTCH,'
         +'    I_SPECIAL=:I_SPECIAL,'
         +'    SUBJ_LINK=:SUBJ_LINK'
         +'    WHERE UNIT_LINK=:UNIT_LINK';
end;

constructor TUNIT.Create;
begin

end;

class procedure TUNIT.DeleteDB(Params: string);
begin

end;

destructor TUNIT.Destroy;
begin

  inherited;
end;

class function TUNIT.ReadDS(AUniQuery: TUniQuery): TUniEngine;
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  Result:=TUNIT.Create;

  with TUNIT(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='UNIT_LINK' then
      begin
        UNITLINK :=Field.AsString;
      end else
      if FieldName='UNIT_CODE' then
      begin
        UNITCODE :=Field.AsString;
      end else
      if FieldName='UNIT_NAME' then
      begin
        UNITNAME :=Field.AsString;
      end else
      if FieldName='UNIT_CALL' then
      begin
        UNITCALL :=Field.AsString;
      end else
      if FieldName='UNIT_ADDR' then
      begin
        UNITADDR :=Field.AsString;
      end else
      if FieldName='UNIT_KIND' then
      begin
        UNITKIND :=Field.AsString;
      end else
      if FieldName='UNIT_LEVL' then
      begin
        UNITLEVL :=Field.AsInteger;
      end else
      if FieldName='UNIT_PREV' then
      begin
        UNITPREV :=Field.AsString;
      end else
      if FieldName='UNIT_MEMO' then
      begin
        UNITMEMO :=Field.AsString;
      end else
      if FieldName='UNIT_ABBR' then
      begin
        UNITABBR :=Field.AsString;
      end else
      if FieldName='UNIT_IDEX' then
      begin
        UNITIDEX :=Field.AsInteger;
      end else
      if FieldName='UNIT_ORDR' then
      begin
        UNITORDR :=Field.AsInteger;
      end else
      if FieldName='HOLD_BANK' then
      begin
        HOLDBANK :=Field.AsString;
      end else
      if FieldName='OTHR_BANK' then
      begin
        OTHRBANK :=Field.AsString;
      end else
      if FieldName='FINA_MTCH' then
      begin
        FINAMTCH :=Field.AsString;
      end else
      if FieldName='BASE_MTCH' then
      begin
        BASEMTCH :=Field.AsString;
      end else
      if FieldName='I_SPECIAL' then
      begin
        ISPECIAL :=Field.AsInteger;
      end else
      if FieldName='SUBJ_LINK' then
      begin
        SUBJLINK :=Field.AsString;
      end;
    end
  end;
end;

class procedure TUNIT.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
var
  I:Integer;
  Field:TField;
  FieldName:string;
begin
  if Result=nil then Exit;

  with TUNIT(Result) do
  begin
    for I:=0 to AUniQuery.Fields.Count-1 do
    begin
      Field:=AUniQuery.Fields.Fields[I];
      //if field.fieldname is not all uppercase,please use uppercase().
      FieldName:=Field.FieldName;
      if FieldName='UNIT_LINK' then
      begin
        UNITLINK :=Field.AsString;
      end else
      if FieldName='UNIT_CODE' then
      begin
        UNITCODE :=Field.AsString;
      end else
      if FieldName='UNIT_NAME' then
      begin
        UNITNAME :=Field.AsString;
      end else
      if FieldName='UNIT_CALL' then
      begin
        UNITCALL :=Field.AsString;
      end else
      if FieldName='UNIT_ADDR' then
      begin
        UNITADDR :=Field.AsString;
      end else
      if FieldName='UNIT_KIND' then
      begin
        UNITKIND :=Field.AsString;
      end else
      if FieldName='UNIT_LEVL' then
      begin
        UNITLEVL :=Field.AsInteger;
      end else
      if FieldName='UNIT_PREV' then
      begin
        UNITPREV :=Field.AsString;
      end else
      if FieldName='UNIT_MEMO' then
      begin
        UNITMEMO :=Field.AsString;
      end else
      if FieldName='UNIT_ABBR' then
      begin
        UNITABBR :=Field.AsString;
      end else
      if FieldName='UNIT_IDEX' then
      begin
        UNITIDEX :=Field.AsInteger;
      end else
      if FieldName='UNIT_ORDR' then
      begin
        UNITORDR :=Field.AsInteger;
      end else
      if FieldName='HOLD_BANK' then
      begin
        HOLDBANK :=Field.AsString;
      end else
      if FieldName='OTHR_BANK' then
      begin
        OTHRBANK :=Field.AsString;
      end else
      if FieldName='FINA_MTCH' then
      begin
        FINAMTCH :=Field.AsString;
      end else
      if FieldName='BASE_MTCH' then
      begin
        BASEMTCH :=Field.AsString;
      end else
      if FieldName='I_SPECIAL' then
      begin
        ISPECIAL :=Field.AsInteger;
      end else
      if FieldName='SUBJ_LINK' then
      begin
        SUBJLINK :=Field.AsString;
      end;
    end
  end;
end;

class function  TUNIT.CopyIt(AUNIT: TUNIT): TUNIT;
begin
  Result:=TUNIT.Create;
  TUNIT.CopyIt(AUNIT,Result)
end;

class procedure TUNIT.CopyIt(AUNIT:TUNIT;var Result:TUNIT);
begin
  if Result=nil then Exit;
  Result.UNITLINK :=AUNIT.UNITLINK;
  Result.UNITCODE :=AUNIT.UNITCODE;
  Result.UNITNAME :=AUNIT.UNITNAME;
  Result.UNITCALL :=AUNIT.UNITCALL;
  Result.UNITADDR :=AUNIT.UNITADDR;
  Result.UNITKIND :=AUNIT.UNITKIND;
  Result.UNITLEVL :=AUNIT.UNITLEVL;
  Result.UNITPREV :=AUNIT.UNITPREV;
  Result.UNITMEMO :=AUNIT.UNITMEMO;
  Result.UNITABBR :=AUNIT.UNITABBR;
  Result.UNITIDEX :=AUNIT.UNITIDEX;
  Result.UNITORDR :=AUNIT.UNITORDR;
  Result.HOLDBANK :=AUNIT.HOLDBANK;
  Result.OTHRBANK :=AUNIT.OTHRBANK;
  Result.FINAMTCH :=AUNIT.FINAMTCH;
  Result.BASEMTCH :=AUNIT.BASEMTCH;
  Result.ISPECIAL :=AUNIT.ISPECIAL;
  Result.SUBJLINK :=AUNIT.SUBJLINK;
end;

end.

